package org.ricks.condition1.entity;

public class Task {

    private int taskId;

    private String title;       // 任务名称
    private int currentValue;   // 当前进度值
    private int targetValue;    // 目标进度值
    private TaskStatus status;  // 任务状态

    public enum TaskStatus {
        IN_PROGRESS, COMPLETED
    }

    // 更新进度并检查状态变化（原子操作）
    public synchronized boolean updateProgress(int newValue) {
        if (status == TaskStatus.COMPLETED) return false;

        currentValue = Math.min(newValue, targetValue);
        boolean isNowCompleted = currentValue >= targetValue;
        if (isNowCompleted) {
            status = TaskStatus.COMPLETED;
        }
        return isNowCompleted;
    }

    public int getTaskId() {
        return taskId;
    }

    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getCurrentValue() {
        return currentValue;
    }

    public void setCurrentValue(int currentValue) {
        this.currentValue = currentValue;
    }

    public int getTargetValue() {
        return targetValue;
    }

    public void setTargetValue(int targetValue) {
        this.targetValue = targetValue;
    }

    public TaskStatus getStatus() {
        return status;
    }

    public void setStatus(TaskStatus status) {
        this.status = status;
    }
}
